#include "pstyledframe.h"
#include <QPainter>

PStyledFrame::PStyledFrame(QWidget *parent)
 : QFrame(parent)
{
}


PStyledFrame::~PStyledFrame()
{
}




/*!
    \fn PStyledFrame::settopLeftPixmap(QPixmap pixmap)
 */
void PStyledFrame::setTopLeftPixmap(QPixmap pixmap)
{
    m_topLeftCornerPixmap = pixmap;
}


/*!
    \fn PStyledFrame::settopRightPixmap(QPixmap pixmap)
 */
void PStyledFrame::setTopRightPixmap(QPixmap pixmap)
{
    m_topRightCornerPixmap = pixmap;
}


/*!
    \fn PStyledFrame::topLeftPixmap()
 */
QPixmap PStyledFrame::topLeftPixmap()
{
    return m_topLeftCornerPixmap;
}


/*!
    \fn PStyledFrame::topRightPixmap()
 */
QPixmap PStyledFrame::topRightPixmap()
{
    return m_topRightCornerPixmap;
}


/*!
    \fn PStyledFrame::bottomLeftPixmap()
 */
QPixmap PStyledFrame::bottomLeftPixmap()
{
    return m_bottomLeftCornerPixmap;
}


/*!
    \fn PStyledFrame::bottomRightPixmap()
 */
QPixmap PStyledFrame::bottomRightPixmap()
{
    return m_bottomRightCornerPixmap;
}


/*!
    \fn PStyledFrame::settopFramePixmap(QPixmap pixmap)
 */
void PStyledFrame::setTopFramePixmap(QPixmap pixmap)
{
    m_topFramePixmap = pixmap;
}


/*!
    \fn PStyledFrame::setBottomFramePixmap(QPixmap pixmap)
 */
void PStyledFrame::setBottomFramePixmap(QPixmap pixmap)
{
    if(pixmap.isNull())qWarning("PStyledFrame::setBottomFramePixmap is null");
    m_bottomFramePixmap = pixmap;
}


/*!
    \fn PStyledFrame::setLeftFramePixmap(QPixmap pixmap)
 */
void PStyledFrame::setLeftFramePixmap(QPixmap pixmap)
{
    m_leftFramePixmap = pixmap;
}


/*!
    \fn PStyledFrame::setRightFramePixmap(QPixmap pixmap)
 */
void PStyledFrame::setRightFramePixmap(QPixmap pixmap)
{
    m_rightFramePixmap = pixmap;
}


/*!
    \fn PStyledFrame::topFramePixmap()
 */
QPixmap PStyledFrame::topFramePixmap()
{
    return m_topFramePixmap;
}


/*!
    \fn PStyledFrame::bottomFramePixmap()
 */
QPixmap PStyledFrame::bottomFramePixmap()
{
    return m_bottomFramePixmap;
}


/*!
    \fn PStyledFrame::leftFramePixmap()
 */
QPixmap PStyledFrame::leftFramePixmap()
{
    return m_leftFramePixmap;
}


/*!
    \fn PStyledFrame::rightFramePixmap()
 */
QPixmap PStyledFrame::rightFramePixmap()
{
    return m_rightFramePixmap;
}


/*!
    \fn PStyledFrame::setBottomLeftPixmap(QPixmap pixmap)
 */
void PStyledFrame::setBottomLeftPixmap(QPixmap pixmap)
{
    m_bottomLeftCornerPixmap = pixmap;
}


/*!
    \fn PStyledFrame::setBottomRightPixmap(QPixmap pixmap)
 */
void PStyledFrame::setBottomRightPixmap(QPixmap pixmap)
{
    m_bottomRightCornerPixmap = pixmap;
}



/*!
    \fn PStyledFrame::paintEvent(QPaintEvent *e)
 */
void PStyledFrame::paintEvent(QPaintEvent *e)
{
//    qDebug("PStyledFrame::paintEvent");
    //qDebug("height :%d %d",height(),height()-m_bottomRightCornerPixmap.height());
    QFrame::paintEvent(e);
    QPainter p(this);
    //p.begin(this);
    //p.setBrush(m_backgroundColor) ;
    p.drawTiledPixmap(m_topLeftCornerPixmap.width(),m_topLeftCornerPixmap.height(),width()-m_topRightCornerPixmap.width()-m_topLeftCornerPixmap.width(),height()-m_topLeftCornerPixmap.height()-m_bottomLeftCornerPixmap.height(),m_backgroundTile);
    if(!m_topFramePixmap.isNull());
     p.drawTiledPixmap(m_topLeftCornerPixmap.width(),0,width()-m_topRightCornerPixmap.width()-10,m_topFramePixmap.height(),m_topFramePixmap);
    if(!m_bottomFramePixmap.isNull()) 
     p.drawTiledPixmap(m_bottomLeftCornerPixmap.width(),height()-m_bottomFramePixmap.height(),width()-m_bottomRightCornerPixmap.width()-m_bottomRightCornerPixmap.width(),m_bottomFramePixmap.height(),m_bottomFramePixmap);
    if(!m_leftFramePixmap.isNull()) 
     p.drawTiledPixmap(0,m_topLeftCornerPixmap.height(),m_leftFramePixmap.width(),height()-m_bottomLeftCornerPixmap.height()*2,m_leftFramePixmap);
    if(!m_rightFramePixmap.isNull()) 
     p.drawTiledPixmap(width()-m_rightFramePixmap.width(),m_topRightCornerPixmap.height(),m_rightFramePixmap.width(),height()-m_bottomRightCornerPixmap.height()*2,m_rightFramePixmap);
    if(!m_topLeftCornerPixmap.isNull())
     p.drawPixmap(0,0,m_topLeftCornerPixmap);
    if(!m_topRightCornerPixmap.isNull())
     p.drawPixmap(width()-m_topRightCornerPixmap.width(),0,m_topRightCornerPixmap);
    if(!m_bottomLeftCornerPixmap.isNull()) 
     p.drawPixmap(0,height()-m_bottomLeftCornerPixmap.height(),m_bottomLeftCornerPixmap);
    if(!m_bottomRightCornerPixmap.isNull()) 
     p.drawPixmap(width()-m_bottomRightCornerPixmap.width(),height()-m_bottomRightCornerPixmap.height(),m_bottomRightCornerPixmap);
    
    p.end();
}


/*!
    \fn PStyledFrame::setBackgroundColor(QColor color)
 */
void PStyledFrame::setBackgroundTile(QPixmap tile)
{
    m_backgroundTile = tile;
}


/*!
    \fn PStyledFrame::getBackgroundColor()
 */
QPixmap PStyledFrame::getBackgroundTile()
{
    return m_backgroundTile;
}
